﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.yy.manager {
    import flash.utils.*;
    import flash.media.*;

    public class SoundManager {

        public static var MAX_LOOP:int = 2147483647;
        private static var _soundManager:SoundManager;

        private var _soundDic:Dictionary;
        private var _soundChannelDic:Dictionary;

        public function SoundManager(){
            if (_soundManager == null){
                _soundManager = this;
                this._soundDic = new Dictionary();
                this._soundChannelDic = new Dictionary();
            } else {
                throw (new Error("实例化单例类出错--SoundManager"));
            };
        }
        public static function get instance():SoundManager{
            if (_soundManager == null){
                _soundManager = new (SoundManager)();
            };
            return (_soundManager);
        }

        public function registerSound(_arg1:Sound, _arg2:int):void{
            if (!this._soundDic[_arg2]){
                this._soundDic[_arg2] = _arg1;
            };
        }
        public function playSound(_arg1:int, _arg2:int=0, _arg3:Number=1, _arg4:int=0):SoundChannel{
            var _local5:SoundTransform;
            if (this._soundDic[_arg1]){
                if (this._soundChannelDic[_arg1]){
                    SoundChannel(this._soundChannelDic[_arg1]).stop();
                };
                _local5 = new SoundTransform(_arg3);
                this._soundChannelDic[_arg1] = Sound(this._soundDic[_arg1]).play(_arg4, _arg2, _local5);
                return (this._soundChannelDic[_arg1]);
            };
            return (null);
        }
        public function stopSound(_arg1:int):void{
            if (this._soundChannelDic[_arg1]){
                SoundChannel(this._soundChannelDic[_arg1]).stop();
            };
        }
        public function getSoundVolume(_arg1:int):Number{
            if (this._soundChannelDic[_arg1]){
                return (SoundChannel(this._soundChannelDic[_arg1]).soundTransform.volume);
            };
            throw (new Error("该声音没有注册或不是播放状态"));
        }
        public function setSoundVolume(_arg1:int, _arg2:Number):void{
            var _local3:SoundTransform;
            if (this._soundChannelDic[_arg1]){
                if (_arg2 < 0){
                    _arg2 = 0;
                };
                if (_arg2 > 1){
                    _arg2 = 1;
                };
                _local3 = new SoundTransform(_arg2);
                SoundChannel(this._soundChannelDic[_arg1]).soundTransform = _local3;
            } else {
                throw (new Error("该声音没有注册或不是播放状态"));
            };
        }
        public function stopAllSound():void{
            if (SoundMixer.areSoundsInaccessible()){
                throw (new Error("无法访问某个播放中的声音"));
            };
            SoundMixer.stopAll();
        }
        public function disposeAllSound():void{
            var _local1:String;
            var _local2:String;
            this.stopAllSound();
            for (_local1 in this._soundDic) {
                if (this._soundDic[_local1]){
                    this._soundDic[_local1] = null;
                    delete this._soundDic[_local1];
                };
            };
            for (_local2 in this._soundChannelDic) {
                if (this._soundChannelDic[_local2]){
                    this._soundChannelDic[_local2] = null;
                    delete this._soundChannelDic[_local2];
                };
            };
        }
        public function get soundChannelDic():Dictionary{
            return (this._soundChannelDic);
        }
        public function get soundDic():Dictionary{
            return (this._soundDic);
        }

    }
}